﻿Imports DirectShowLib
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Drawing.Imaging
Imports UCBase
Imports System.Windows.Forms
Imports System.Drawing

Public Class BaseCamera
    Implements ISampleGrabberCB
    Implements IDisposable
    Implements I_ImageExchange

    Implements UCBase.I_LoadSave
    Implements UCBase.I_EditMode
    <DllImport("Kernel32.dll", EntryPoint:="RtlMoveMemory")> _
    Private Shared Sub CopyMemory(ByVal Destination As IntPtr, ByVal Source As IntPtr, <MarshalAs(UnmanagedType.U4)> ByVal Length As Integer)
    End Sub

    Private capDevices As DsDevice()
    Private m_FilterGraph As IFilterGraph2 = Nothing
    Private m_VidControl As IAMVideoControl = Nothing
    Private m_pinStill As IPin = Nothing
    Private m_rot As DsROTEntry = Nothing
    Private m_ip As IntPtr = IntPtr.Zero
    Private m_CamControl As IAMCameraControl = Nothing
    Private m_VideoProcAmp As IAMVideoProcAmp = Nothing
    Private M_Capture As IAMStreamConfig = Nothing
    Private m_PictureReady As ManualResetEvent = Nothing
    Private m_WantOne As Boolean = False
    Private m_videoWidth As Integer
    Private m_videoHeight As Integer
    Private m_stride As Integer
    Private m_bits As Integer
    Private m_ipBuffer As IntPtr = IntPtr.Zero
    Private M_ResolutionModes As New Collection
    Private SelectedDevice As Integer
    Private SelectedPreviewMode As Integer
    Private SelectedCaptureMode As Integer
    'Public Event ImageReady(ByVal Image As Bitmap)
    Private M_VidWin As PictureBox
    Private M_RUN As Boolean = False
    Private BackPic As New BackgroundCreator
    Private CanPreview As Boolean = False
    Private InternalPreview As Boolean = True
    Private HaveVidWin As Boolean = False
    Private Mov As New Mover
    Private M_Edit As Boolean = True

    Private M_ImageEnabled As Boolean = False
    Private M_ImageConnected As Boolean = False
    Private M_auto_Trigger As Boolean = False

    Private Sub Camera_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

    End Sub

    Private Sub Camera_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)
        Dim C As Integer = 0
        For Each Dev As DsDevice In capDevices
            ComboBox1.Items.Add("[" & C & "] " & Dev.Name)
            C = C + 1
        Next
        m_PictureReady = New ManualResetEvent(False)
        'Dim Viewer As ExternalViewer
        Me.BackgroundImage = BackPic.CreatePic(Me.Width, Me.Height)
        Mov.Connect(Me)
        TextBox1.Text = Me.Name
        Label7.Left = -20000

    End Sub
    Public Function GetSettings() As String
        Return "Device=1,Mode=1"
    End Function
    Private Sub Camera_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Width = 320
        Me.Height = 345
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        SelectedDevice = ComboBox1.SelectedIndex
        GetResolutions()
    End Sub
    Private Sub GetResolutions()
        Dim hr As Integer
        Dim dev As DsDevice = capDevices(SelectedDevice)
        Dim capFilter As IBaseFilter = Nothing
        m_FilterGraph = TryCast(New FilterGraph(), IFilterGraph2)

        Try
            hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, Nothing, dev.Name, capFilter)
            DsError.ThrowExceptionForHR(hr)
            m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0)
            If m_pinStill Is Nothing Then
                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0)
            End If
            If m_pinStill Is Nothing Then
                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0)
            End If

            Dim streamConfig As IAMStreamConfig = DirectCast(m_pinStill, IAMStreamConfig)
            Dim searchmedia As AMMediaType = Nothing
            Dim ptr As IntPtr

            Dim piCount As Integer, piSize As Integer
            hr = streamConfig.GetNumberOfCapabilities(piCount, piSize)
            ptr = Marshal.AllocCoTaskMem(piSize)
            For i As Integer = 0 To piCount - 1
                hr = streamConfig.GetStreamCaps(i, searchmedia, ptr)
                Dim vinfo As New VideoInfoHeader()
                Marshal.PtrToStructure(searchmedia.formatPtr, vinfo)
                If vinfo.BmiHeader.Width > 0 Then
                    ComboBox2.Items.Add("[" & i & "] = " & vinfo.BmiHeader.Width & " X " & vinfo.BmiHeader.Height & "(" & vinfo.BmiHeader.BitCount & ")" & " FPS:" & CInt(10000000 / vinfo.AvgTimePerFrame))
                    ComboBox2.Enabled = True
                End If
            Next

        Catch
        End Try

        If m_FilterGraph IsNot Nothing Then
            Marshal.ReleaseComObject(m_FilterGraph)
            m_FilterGraph = Nothing
        End If

        If m_pinStill IsNot Nothing Then
            Marshal.ReleaseComObject(m_pinStill)
            m_pinStill = Nothing
        End If
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        M_RUN = False
        Dim str As String = ComboBox2.SelectedItem
        Dim a As Integer = str.IndexOf("[") + 1
        Dim b As Integer = str.IndexOf("]")
        Dim l As Integer = b - a
        Dim n As String = str.Substring(a, l)
        SelectedPreviewMode = CInt(Val(n))
        CanPreview = True
        Led2.State = Led.LedState.Led_On
        CloseInterfaces()
        SetupGraph()
    End Sub

    Private Sub SetupGraph()
        Dim hr As Integer

        Dim sampGrabber As ISampleGrabber = Nothing
        Dim capFilter As IBaseFilter = Nothing
        Dim pCaptureOut As IPin = Nothing
        Dim pSampleIn As IPin = Nothing
        Dim pRenderIn As IPin = Nothing
        Dim dev As DsDevice = capDevices(SelectedDevice)
        ' Get the graphbuilder object
        m_FilterGraph = TryCast(New FilterGraph(), IFilterGraph2)

        Try
#If DEBUG Then
            m_rot = New DsROTEntry(m_FilterGraph)
#End If
            ' add the video input device
            hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, Nothing, dev.Name, capFilter)
            DsError.ThrowExceptionForHR(hr)

            ' Set up controls
            m_CamControl = TryCast(capFilter, IAMCameraControl)

            m_VideoProcAmp = TryCast(capFilter, IAMVideoProcAmp)

            If CheckBox1.Checked Then
                ' Find the still pin
                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0)

                ' Didn't find one.  Is there a preview pin?
                If m_pinStill Is Nothing Then
                    m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0)
                End If
            End If

            ' Still haven't found one.  Need to put a splitter in so we have
            ' one stream to capture the bitmap from, and one to display.  Ok, we
            ' don't *have* to do it that way, but we are going to anyway.
            If m_pinStill Is Nothing Then
                Dim pRaw As IPin = Nothing
                Dim pSmart As IPin = Nothing

                ' There is no still pin
                m_VidControl = Nothing

                ' Add a splitter
                Dim iSmartTee As IBaseFilter = DirectCast(New SmartTee(), IBaseFilter)

                Try
                    hr = m_FilterGraph.AddFilter(iSmartTee, "SmartTee")
                    DsError.ThrowExceptionForHR(hr)

                    ' Find the find the capture pin from the video device and the
                    ' input pin for the splitter, and connnect them
                    pRaw = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0)
                    pSmart = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0)

                    hr = m_FilterGraph.Connect(pRaw, pSmart)
                    DsError.ThrowExceptionForHR(hr)

                    ' Now set the capture and still pins (from the splitter)
                    m_pinStill = DsFindPin.ByName(iSmartTee, "Preview")
                    pCaptureOut = DsFindPin.ByName(iSmartTee, "Capture")

                    ' If any of the default config items are set, perform the config
                    ' on the actual video device (rather than the splitter)
                    'If iHeight + iWidth + iBPP > 0 Then
                    SetConfigParms(pRaw)
                    'End If
                Finally
                    If pRaw IsNot Nothing Then
                        Marshal.ReleaseComObject(pRaw)
                    End If
                    If pRaw IsNot pSmart Then
                        Marshal.ReleaseComObject(pSmart)
                    End If
                    If pRaw IsNot iSmartTee Then
                        Marshal.ReleaseComObject(iSmartTee)
                    End If
                End Try
            Else
                ' Get a control pointer (used in Click())
                m_VidControl = TryCast(capFilter, IAMVideoControl)
                pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0)

                M_Capture = TryCast(pCaptureOut, IAMStreamConfig)

                ' If any of the default config items are set

                'If iHeight + iWidth + iBPP > 0 Then
                SetConfigParms(m_pinStill)
                'End If
            End If

            ' Get the SampleGrabber interface
            sampGrabber = TryCast(New SampleGrabber(), ISampleGrabber)

            ' Configure the sample grabber
            Dim baseGrabFlt As IBaseFilter = TryCast(sampGrabber, IBaseFilter)
            ConfigureSampleGrabber(sampGrabber)
            pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0)

            ' Get the default video renderer
            Dim pRenderer As IBaseFilter = TryCast(New VideoRendererDefault(), IBaseFilter)
            hr = m_FilterGraph.AddFilter(pRenderer, "Renderer")
            DsError.ThrowExceptionForHR(hr)

            pRenderIn = DsFindPin.ByDirection(pRenderer, PinDirection.Input, 0)

            ' Add the sample grabber to the graph
            hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber")
            DsError.ThrowExceptionForHR(hr)

            If m_VidControl Is Nothing Then
                ' Connect the Still pin to the sample grabber
                hr = m_FilterGraph.Connect(m_pinStill, pSampleIn)
                DsError.ThrowExceptionForHR(hr)

                ' Connect the capture pin to the renderer
                hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn)
                DsError.ThrowExceptionForHR(hr)
            Else
                ' Connect the capture pin to the renderer
                hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn)
                DsError.ThrowExceptionForHR(hr)

                ' Connect the Still pin to the sample grabber
                hr = m_FilterGraph.Connect(m_pinStill, pSampleIn)
                DsError.ThrowExceptionForHR(hr)
            End If

            ' Learn the video properties
            SaveSizeInfo(sampGrabber)
            ConfigVideoWindow(M_VidWin)
            ' Start the graph
            Dim mediaCtrl As IMediaControl = TryCast(m_FilterGraph, IMediaControl)
            hr = mediaCtrl.Run()
            DsError.ThrowExceptionForHR(hr)
        Finally
            If sampGrabber IsNot Nothing Then
                Marshal.ReleaseComObject(sampGrabber)
                sampGrabber = Nothing
            End If
            If pCaptureOut IsNot Nothing Then
                Marshal.ReleaseComObject(pCaptureOut)
                pCaptureOut = Nothing
            End If
            If pRenderIn IsNot Nothing Then
                Marshal.ReleaseComObject(pRenderIn)
                pRenderIn = Nothing
            End If
            If pSampleIn IsNot Nothing Then
                Marshal.ReleaseComObject(pSampleIn)
                pSampleIn = Nothing
            End If
        End Try
        M_RUN = True
    End Sub
    Private Sub ConfigureSampleGrabber(ByVal sampGrabber As ISampleGrabber)
        Dim hr As Integer
        Dim media As New AMMediaType()

        ' Set the media type to Video/RBG24
        media.majorType = MediaType.Video
        media.subType = MediaSubType.RGB24
        media.formatType = FormatType.VideoInfo
        hr = sampGrabber.SetMediaType(media)
        DsError.ThrowExceptionForHR(hr)

        DsUtils.FreeAMMediaType(media)
        media = Nothing

        ' Configure the samplegrabber
        hr = sampGrabber.SetCallback(Me, 1)
        DsError.ThrowExceptionForHR(hr)
    End Sub
    Private Sub SaveSizeInfo(ByVal sampGrabber As ISampleGrabber)
        Dim hr As Integer

        ' Get the media type from the SampleGrabber
        Dim media As New AMMediaType()

        hr = sampGrabber.GetConnectedMediaType(media)
        DsError.ThrowExceptionForHR(hr)

        If (media.formatType <> FormatType.VideoInfo) OrElse (media.formatPtr = IntPtr.Zero) Then
            Throw New NotSupportedException("Unknown Grabber Media Format")
        End If

        ' Grab the size info
        Dim videoInfoHeader As VideoInfoHeader = DirectCast(Marshal.PtrToStructure(media.formatPtr, GetType(VideoInfoHeader)), VideoInfoHeader)
        m_videoWidth = videoInfoHeader.BmiHeader.Width
        m_videoHeight = videoInfoHeader.BmiHeader.Height
        m_stride = m_videoWidth * (videoInfoHeader.BmiHeader.BitCount / 8)
        m_bits = videoInfoHeader.BmiHeader.BitCount
        DsUtils.FreeAMMediaType(media)
        media = Nothing
    End Sub

    Private Sub ConfigVideoWindow(ByVal hControl As Control)
        Dim hr As Integer
        If InternalPreview = True Then hControl = PictureBox1
        Dim ivw As IVideoWindow = TryCast(m_FilterGraph, IVideoWindow)

        ' Set the parent
        hr = ivw.put_Owner(hControl.Handle)
        DsError.ThrowExceptionForHR(hr)

        ' Turn off captions, etc
        hr = ivw.put_WindowStyle(WindowStyle.Child Or WindowStyle.ClipChildren Or WindowStyle.ClipSiblings)
        DsError.ThrowExceptionForHR(hr)

        ' Yes, make it visible
        If InternalPreview = False Then
            hr = ivw.put_Visible(OABool.True)
            DsError.ThrowExceptionForHR(hr)
            If HaveVidWin = True Then Led1.State = Led.LedState.Led_On
        Else
            hr = ivw.put_Visible(OABool.False)
            DsError.ThrowExceptionForHR(hr)
        End If
        ' Move to upper left corner
        Dim rc As Rectangle = hControl.ClientRectangle
        Dim r As Double = m_videoWidth / m_videoHeight
        Dim w As Integer = hControl.Height * r
        Dim L As Integer = (hControl.Width / 2) - (w / 2)
        hr = ivw.SetWindowPosition(L, 0, w, hControl.Height)

        DsError.ThrowExceptionForHR(hr)
    End Sub
    ' Set the Framerate, and video size
    Private Sub SetConfigParms(ByVal pStill As IPin)
        Dim hr As Integer
        Dim streamConfig As IAMStreamConfig = DirectCast(pStill, IAMStreamConfig)
        Dim searchmedia As AMMediaType = Nothing
        Dim CorectvidFormat As New AMMediaType()
        Dim ptr As IntPtr

        Dim piCount As Integer, piSize As Integer
        hr = streamConfig.GetNumberOfCapabilities(piCount, piSize)
        ptr = Marshal.AllocCoTaskMem(piSize)
        For i As Integer = 0 To piCount - 1
            hr = streamConfig.GetStreamCaps(i, searchmedia, ptr)
            Dim v As New VideoInfoHeader()
            Marshal.PtrToStructure(searchmedia.formatPtr, v)
            If i = SelectedPreviewMode Then
                CorectvidFormat = searchmedia
            End If
        Next
        hr = streamConfig.SetFormat(CorectvidFormat)
    End Sub
    Private Sub CloseInterfaces()
        Dim hr As Integer

        Try
            If m_FilterGraph IsNot Nothing Then
                Dim mediaCtrl As IMediaControl = TryCast(m_FilterGraph, IMediaControl)

                ' Stop the graph
                hr = mediaCtrl.[Stop]()
            End If
        Catch ex As Exception
            Debug.WriteLine(ex)
        End Try

        If m_FilterGraph IsNot Nothing Then
            Marshal.ReleaseComObject(m_FilterGraph)
            m_FilterGraph = Nothing
        End If

        If m_VidControl IsNot Nothing Then
            Marshal.ReleaseComObject(m_VidControl)
            m_VidControl = Nothing
        End If

        If m_pinStill IsNot Nothing Then
            Marshal.ReleaseComObject(m_pinStill)
            m_pinStill = Nothing
        End If
    End Sub

    Private Function ISampleGrabberCB_SampleCB(ByVal SampleTime As Double, ByVal pSample As IMediaSample) As Integer Implements ISampleGrabberCB.SampleCB
        Marshal.ReleaseComObject(pSample)
        Return 0
    End Function

    ''' <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary>
    Private Function ISampleGrabberCB_BufferCB(ByVal SampleTime As Double, ByVal pBuffer As IntPtr, ByVal BufferLen As Integer) As Integer Implements ISampleGrabberCB.BufferCB
        ' Note that we depend on only being called once per call to Click.  Otherwise
        ' a second call can overwrite the previous image.
        Debug.Assert(BufferLen = Math.Abs(m_stride) * m_videoHeight, "Incorrect buffer length")

        If m_WantOne Then
            m_WantOne = False
            Debug.Assert(m_ipBuffer <> IntPtr.Zero, "Unitialized buffer")

            ' Save the buffer
            CopyMemory(m_ipBuffer, pBuffer, BufferLen)

            ' Picture is ready.
            m_PictureReady.[Set]()
        End If

        Return 0
    End Function
    Public Sub GetImage()
        If M_RUN = False Then Exit Sub
        If (Trigger.Connected And Trigger.SocketsEnable) Or M_auto_Trigger = True Then
            Led8.State = Led.LedState.Led_On
            Timer2.Enabled = False
            If BackgroundWorker1.IsBusy = False Then
                BackgroundWorker1.RunWorkerAsync()
            End If
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Timer2.Enabled = False
        Led8.State = Led.LedState.Led_Off
    End Sub
    Public ReadOnly Property Running() As Boolean
        Get
            Return M_RUN
        End Get
    End Property
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim hr As Integer

        ' get ready to wait for new image
        m_PictureReady.Reset()
        m_ipBuffer = Marshal.AllocCoTaskMem(Math.Abs(m_stride) * m_videoHeight)
        Try
            m_WantOne = True
            If m_VidControl IsNot Nothing Then
                hr = m_VidControl.SetMode(m_pinStill, VideoControlFlags.Trigger)
                DsError.ThrowExceptionForHR(hr)
            End If
            If Not m_PictureReady.WaitOne(9000, False) Then
                Throw New Exception("Timeout waiting to get picture")
            End If
        Catch
            Marshal.FreeCoTaskMem(m_ipBuffer)
            m_ipBuffer = IntPtr.Zero
            'Throw
        End Try
        If m_ip <> IntPtr.Zero Then
            Marshal.FreeCoTaskMem(m_ip)
            m_ip = IntPtr.Zero
        End If
        m_ip = m_ipBuffer
        Dim pf As PixelFormat
        If m_bits = 24 Then pf = PixelFormat.Format24bppRgb
        If m_bits = 16 Then pf = PixelFormat.Format16bppRgb555
        Dim b As New Bitmap(m_videoWidth, m_videoHeight, m_stride, pf, m_ip)
        b.RotateFlip(RotateFlipType.RotateNoneFlipY)

        If b.PixelFormat <> PixelFormat.Format24bppRgb Then
            Dim temp As Bitmap = AForge.Imaging.Image.Clone(b, PixelFormat.Format24bppRgb)
            b.Dispose()
            b = temp
        End If

        e.Result = b
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        Timer2.Enabled = True
        If ImageOut.Connected And ImageOut.SocketsEnable Then
            RaiseEvent ImageReady(e.Result)
            If M_auto_Trigger = True Then
                GetImage()
            End If
        End If
    End Sub
    Public Property VideoContainer() As PictureBox
        Get
            Return M_VidWin
        End Get
        Set(ByVal value As PictureBox)
            M_VidWin = value
        End Set
    End Property
    Public Function GetCameraCantrol() As IAMCameraControl
        Return m_CamControl
    End Function
    Private Sub Preview_Connect() Handles Preview.Connect
        Dim s As Socket = Preview.Remote
        'Dim M As Monitor = s.Parent
        'M_VidWin = M.PictureBox1
        InternalPreview = False
        HaveVidWin = True
        Led1.State = Led.LedState.Led_On
        If CanPreview = True Then
            Led2.State = Led.LedState.Led_On
            ConfigVideoWindow(M_VidWin)
        End If
    End Sub

    Private Sub Preview_Disconnect() Handles Preview.Disconnected
        M_VidWin = Nothing
        HaveVidWin = False
        Led1.State = Led.LedState.Led_Off
        If CanPreview = True Then
            InternalPreview = True
            ConfigVideoWindow(PictureBox1)

        End If
    End Sub

    Private Sub Button3D1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D1.Click
        If CanPreview = True Then
            If Led2.State = Led.LedState.Led_On Then
                Led2.State = Led.LedState.Led_Off
                InternalPreview = True
                If HaveVidWin = True Then
                    ConfigVideoWindow(M_VidWin)
                Else
                    ConfigVideoWindow(PictureBox1)
                End If
            Else
                InternalPreview = False
                If HaveVidWin = True Then
                    Led2.State = Led.LedState.Led_On
                    ConfigVideoWindow(M_VidWin)
                Else
                    ConfigVideoWindow(PictureBox1)
                End If
            End If
        End If
    End Sub
    Private Sub Button3D5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D5.Click
        If CanPreview = True Then
            If ImageOut.SocketsEnable = False Then
                ImageOut.SocketsEnable = True
                Trigger.SocketsEnable = True
                GetImage()
            Else
                ImageOut.SocketsEnable = False
                Trigger.SocketsEnable = False
            End If
        End If
    End Sub

    Private Sub CameraControl_Connect() Handles CameraControl.Connect
        If CanPreview = True Then
            Dim s As Socket = CameraControl.Remote
            'Dim C As CameraControl = s.Parent
            'C.SetupControls(Me)
        End If
    End Sub

    Private Sub Button3D2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D2.Click
        If M_auto_Trigger = False Then
            M_auto_Trigger = True
            Led9.State = Led.LedState.Led_On
            ImageOut.SocketsEnable = True
            GetImage()
        Else
            M_auto_Trigger = False
            Led9.State = Led.LedState.Led_Off
        End If

    End Sub

    Private Sub ImageOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageOut.Click

    End Sub

    Public Event ImageReady(ByVal Image As System.Drawing.Bitmap) Implements I_ImageExchange.ImageOut1

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
    Public Function GetSettings1() As String Implements UCBase.I_LoadSave.GetSettings
        Return "1,1"
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub

    'Public Event ImageReady(ByVal Image As System.Drawing.Bitmap) Implements UniCamBase.I_ImageExchange.ImageReady

    Public Sub SetEditMode(ByVal Mode As UCBase.Diagram.EditMode) Implements UCBase.I_EditMode.SetEditMode

        If Mode = Diagram.EditMode.Unlocked Then
            M_Edit = True
            Mov.EditMode = True
            ComboBox1.Enabled = True
            ComboBox2.Enabled = True
            TextBox1.Left = 15
            TextBox1.Visible = True
            Label7.Left = -200
            Label7.Visible = False
        Else
            M_Edit = False
            Mov.EditMode = False
            ComboBox1.Enabled = False
            ComboBox2.Enabled = False
            TextBox1.Visible = False
            TextBox1.Left = -200
            Label7.Text = TextBox1.Text
            Label7.Visible = True
            Label7.Left = 15
        End If
    End Sub
End Class
